﻿using System.Collections.Generic;

namespace HW3
{
  
 class CalculationOfOrders
    {
        private readonly int _a = 0;
        private readonly int _b = 0;
        private readonly List<int> _calculationList = new List<int>();
        private readonly int[] _indexOfCalculation = new int[9];
 
        public CalculationOfOrders(int num1,int num2)
        {
            for (; _a < 3; _a++)
            {
                for (_b = 0; _b < 3; _b++)
                   _calculationList.Add(_a * num1+ _b * num2);
            }
            _calculationList.Sort();
        }

        public List<int> GetCalculationList()
        {
            return _calculationList;
        }

        public void BuildIndexCalculation(int num)
        {
            var value = 0;
            for (int i = 0; i < _indexOfCalculation.Length; i++)
            {
                _indexOfCalculation[i] = value;
                value += num;
            }
        }

        public int CheckAmountInCalculation(int left)
        {
            if ((_indexOfCalculation[0] <= left) && (_indexOfCalculation[1] > left))
                return _calculationList[8];
            else if ((_indexOfCalculation[1] <= left) && (_indexOfCalculation[2] > left))
                return _calculationList[7];
            else if ((_indexOfCalculation[2] <= left) && (_indexOfCalculation[3] > left))
                return _calculationList[6];
            else if ((_indexOfCalculation[3] <= left) && (_indexOfCalculation[4] > left))
                return _calculationList[5];
            else if ((_indexOfCalculation[4] <= left) && (_indexOfCalculation[5] > left))
                return _calculationList[4];
            else if ((_indexOfCalculation[5] <= left) && (_indexOfCalculation[6] > left))
                return _calculationList[3];
            else if ((_indexOfCalculation[6] <= left) && (_indexOfCalculation[7] > left))
                return _calculationList[2];
            else if ((_indexOfCalculation[7] <= left) && (_indexOfCalculation[8] > left))
                return _calculationList[1];
            else return 0;
        }
    }
}

